
package org.soekrat.engine.ontology.ptable;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.soekrat.engine.SoekratName;

public final class FactorMatchResult  
{
  private final Set<ProductTableFactor> m_rowf=
    new HashSet<ProductTableFactor>();
  
  private final Set<ProductTableFactor> m_colf=
    new HashSet<ProductTableFactor>();
  
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  FactorMatchResult(){}
  
  void add(List<ProductTableFactor> f, boolean row)
  {
    if (row) m_rowf.addAll(f);
    else     m_colf.addAll(f);
  }
  
  /**
   * <p>
   *   
   * </p>
   * @return
   */
  public boolean both(){ return !m_rowf.isEmpty() && !m_colf.isEmpty(); }
  
  public List<FactorPair> getPairs()
  {
    List<FactorPair> retVal=new ArrayList<FactorPair>();
    
    if (!both()) return retVal;
    
    SoekratName[] rl=m_rowf.toArray(SoekratName.EMPTY_ARRAY);
    SoekratName[] cl=m_colf.toArray(SoekratName.EMPTY_ARRAY);
    
    int n=rl.length;
    int m=cl.length;
    for (int i=0; i<n; i++)
    {
      SoekratName rn=rl[i];
      for (int j=0; j<m; j++)
      {
        SoekratName cn=cl[j];
        retVal.add(new FactorPair(rn, cn));
      }
    }
    
    return retVal;
  }
  
}
